package com.bicntech.admin.controller.airport;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bicntech.common.core.controller.SuperController;
import com.bicntech.common.core.domain.R;
import com.bicntech.system.dto.*;
import com.bicntech.system.service.OutfieldVehicleEquipmentInspectService;
import com.bicntech.system.vo.OutfieldTypeStatisticsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/outfield-vehicle-equipment-inspect")
public class OutfieldVehicleEquipmentInspectController extends SuperController {

    @Resource
    private OutfieldVehicleEquipmentInspectService outfieldVehicleEquipmentInspectService;


    @PostMapping(value = "/listByPage")
    public R<IPage<OutfieldVehicleEquipmentInspectDTO>> listByPage(@RequestBody OutfieldInspectQueryDTO query) {
        IPage<OutfieldVehicleEquipmentInspectDTO> pageList = outfieldVehicleEquipmentInspectService.listOutfieldVehicleEquipmentInspectsByPage(packPage(), query);
        return R.ok(pageList);
    }

    @PostMapping(value = "/listNoPage")
    public R<List<OutfieldVehicleEquipmentInspectDTO>> listNoPage(@RequestBody OutfieldVehicleEquipmentInspectDTO outfieldVehicleEquipmentInspectDTO) {
        List<OutfieldVehicleEquipmentInspectDTO> outfieldVehicleEquipmentInspectList = outfieldVehicleEquipmentInspectService.listOutfieldVehicleEquipmentInspects(outfieldVehicleEquipmentInspectDTO);
        return R.ok(outfieldVehicleEquipmentInspectList);
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/queryById")
    public R<OutfieldVehicleEquipmentInspectDTO> queryById(@RequestParam(name = "id") Long id) {
        OutfieldVehicleEquipmentInspectDTO outfieldVehicleEquipmentInspectDTO = outfieldVehicleEquipmentInspectService.getOutfieldVehicleEquipmentInspectById(id);
        return R.ok(outfieldVehicleEquipmentInspectDTO);
    }

    @PostMapping(value = "/add")
    public R<?> addOutfieldVehicleEquipmentInspect(@RequestBody @Validated OutfieldInspectAddDTO outfieldVehicleEquipmentInspectDTO) {
        return R.ok(outfieldVehicleEquipmentInspectService.addOutfieldVehicleEquipmentInspect(outfieldVehicleEquipmentInspectDTO));
    }

    @PutMapping(value = "/edit")
    public R<?> edit(@RequestBody @Validated OutfieldInspectWorkerDTO inspectWorkerDTO) {
        outfieldVehicleEquipmentInspectService.updateOutfieldVehicleEquipmentInspect(inspectWorkerDTO);
        return R.ok("提交成功!");
    }
    /**
     * 表头修改
     */
    @PutMapping(value = "/updateHeadById")
    public R<?> updateHeadById(@RequestBody @Validated OutfieldInspectAddDTO inspectWorkerDTO) {
        outfieldVehicleEquipmentInspectService.updateHeadById(inspectWorkerDTO);
        return R.ok("提交成功!");
    }

    /**
     * 工单废弃
     */
    @PutMapping(value = "/updateStateById/{id}")
    public R<?> disuseById(@PathVariable("id") Long id) {
        outfieldVehicleEquipmentInspectService.disuseById(id);
        return R.ok("提交成功!");
    }




    @DeleteMapping(value = "/delete/{id}")
    public R<?> delete(@PathVariable Long id) {
        outfieldVehicleEquipmentInspectService.deleteOutfieldVehicleEquipmentInspectById(id);
        return R.ok("删除成功!");
    }

    /**
     * 外场工单类型统计
     */
    @GetMapping(value = "/typeStatistics")
    public R<List<OutfieldTypeStatisticsVO>> typeStatistics() {
        return R.ok(outfieldVehicleEquipmentInspectService.typeStatistics());
    }



}
